package com.bxshey.happyTown.config;


import com.bxshey.happyTown.exception.BusinessException;
import com.bxshey.happyTown.result.Result;



import lombok.extern.slf4j.Slf4j;



import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;




//异常处理器 ，系统中所有的异常都会被集中在这处理
@RestControllerAdvice
@Slf4j
public class ProjectExceptionAdvice{


    //第三方异常 即找不到问题时
    @ExceptionHandler(Exception.class)
    public Result<?> doException(Exception ex) {
        System.out.println(ex);
           return Result.error();
    }


    //业务出现的异常后者错误
    @ExceptionHandler(value = {BusinessException.class})
    public Result<?> doBusinessException(BusinessException ex) {
        System.out.println(ex);
        return Result.error(ex.getCode(),ex.getMessage());
    }

}
